home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / Xteq X-Setup / xqdcXSP-Setup-EN.exe / {app} / plugins / svho IE Edit Context Menu.xpl < prev    next >
Text File  |  2003-11-19  |  13KB  |  435 lines

  1. "FILE"="Xteq Systems X-Setup Plugin 6.0"
  2. "TYPE"="8"
  3. "COUNT"="3"
  4. "TEXT 1"="&Edit"
  5. "TEXT 2"="&Add new"
  6. "TEXT 3"="&Delete"
  7. "UIPATH"="Internet\Internet Explorer\Context Menu Entries"
  8. "NAME"="Editor"
  9. "LANGUAGE"="VBScript"
  10. "DESCRIPTION 1"="This plug-in edits entries in Internet Explorer context menu. You may need to restart Internet Explorer to make it work."
  11. "DESCRIPTION 2"="NOTE #1: Entries, that begin with '[]' are unvisible."
  12. "DESCRIPTION 3"="NOTE #2: Entries, that begin with '!!' are visible, but IE shows them not, because they are useless (without default URL)."
  13. "DESCRIPTION 4"="NOTE #3: To only rename the entry, click 'Edit', change the name, click 'OK' and then 'Cancel'.
  14. "VERSION"="1.02"
  15. "AUTHOR"="Svyatoslav Holub"
  16. "CONTACTURL"="mailto:jobvonzuhause@everyday.com"
  17. "COPYRIGHT"="This plug-in is Freeware. Use at your own risk!"
  18. "COMMENT 1"="Tested on Windows 98SE with Internet Explorer 6.0"
  19. "ADMINRIGHTS"="0"
  20. "OSVERSION"="0111111"
  21.  
  22. visibleMenuExt="HKCU\Software\Microsoft\Internet Explorer\MenuExt"
  23. unvisibleMenuExt="HKCU\Software\Microsoft\Internet Explorer\MenuExt-"
  24.  
  25. const vMark ="[] "  'indicates unvisibility
  26. const uMark ="!! "              'indicates useless
  27.  
  28. dim visibleCount, unvisibleCount
  29. dim visibleMenuExists, unvisibleMenuExists
  30. dim vMarkLength, uMarkLength
  31. dim trueNames()
  32.  
  33.  
  34. Sub Plugin_Initialize
  35.  vMarkLength = Len(vMark)
  36.  uMarkLength = Len(uMark)
  37.  
  38. 'Clear listbox
  39.  elemNumber = visibleCount + unvisibleCount
  40.  For l = 1 to elemNumber
  41.    SetUIElement l, ""
  42.  Next
  43.  
  44. 'Clear names array
  45.  Redim trueNames(0)
  46.  
  47.  visibleCount = 0
  48.  unvisibleCount = 0
  49.  
  50.  
  51.  visibleMenuExists = RegPathExists(visibleMenuExt)
  52.  unvisibleMenuExists = RegPathExists(unvisibleMenuExt)
  53.  
  54.  dim  falseNames
  55.  If  visibleMenuExists = true Then
  56.   visibleCount=RegEnumPaths(visibleMenuExt)
  57.   If CBool (visibleCount) Then listAddNew visibleCount, 0, true, falseNames
  58.  End If
  59.  
  60.  If  unvisibleMenuExists = true Then
  61.   unvisibleCount=RegEnumPaths(unvisibleMenuExt)
  62.   If CBool (unvisibleCount) Then listAddNew unvisibleCount, visibleCount, false, falseNames
  63.  End If
  64.  
  65.  If falseNames <> "" Then MsgWarning "Following context menu names begin with " & _
  66.           vMark & "or " & uMark & ":" & vbCrLf & vbCrLf & _
  67.           falseNames & vbCrLf & "The plug-in uses this characters " & _
  68.           "to indicate entry properties." & vbCrLf & _
  69.           "Please rename this entries with 'Edit'-button."
  70.  'If visibleCount + unvisibleCount = 0 Then Disable
  71. End Sub
  72.  
  73. Sub listAddNew (elemCounter, listCounter, visibilityFlag, ByRef falseNames)
  74.  For i=1 to elemCounter
  75.    extText=RegEnumElement(i)
  76.    j = i + listCounter
  77.    Redim Preserve trueNames(j)
  78.    trueNames(j) = extText
  79.    If Len(extText) > 1 Then _
  80.      If Left(extText,2)=Left(uMark,2) OR Left(extText,2)=Left(vMark,2) Then _
  81.        falseNames = falseNames & vbTab & extText & vbCrLf
  82.    If visibilityFlag = false Then
  83.        SetUIElement j, vMark & extText
  84.    Else
  85.        If RegReadValue(visibleMenuExt & "\" & extText & "\" & "@")="" Then
  86.         SetUIElement j, uMark & extText
  87.        Else
  88.         SetUIElement j, extText
  89.        End If
  90.    End If
  91.  Next
  92. End Sub
  93.  
  94.  
  95. Sub Plugin_Apply(ElementIndex,ElementSubIndex)
  96. 'Nothing to do, if IE settings in Registry were meantime for example manual changed.
  97.  If RegistryChanged = true Then Exit Sub
  98.  
  99.  Select Case ElementIndex
  100.  Case 1 'edit
  101.   If ElementSubIndex <> 0 Then editEntry ElementSubIndex
  102.  Case 2 'add new
  103.   addEntry
  104.  Case 3 'delete
  105.   If ElementSubIndex <> 0 Then deleteEntry ElementSubIndex
  106.  Case Else
  107.   'not possible
  108.  End Select
  109.     
  110. End Sub
  111.  
  112.  
  113. Sub editEntry (entryIndex)
  114.  
  115. changed = false
  116.  
  117. If entryIndex <> 0 Then
  118.   If entryIndex > visibleCount Then
  119.     fullName = unvisibleMenuExt & "\" & trueNames(entryIndex)
  120.     visibility = false
  121.   Else
  122.     fullName = visibleMenuExt & "\" & trueNames(entryIndex)
  123.     visibility = true
  124.   End If
  125. Else
  126.   visibility = true
  127. End If
  128.   
  129.   dim editValues(3)
  130.   editValues(3) = visibility
  131.   
  132.   'show input windows
  133.   For i=1 to 4
  134.     answer = DataInput (i, fullName, entryIndex, editValues)
  135.     If IsEmpty(answer) = true Then Exit For
  136.   Next
  137.  
  138.   If IsEmpty(editValues(0)) = true Then Exit Sub
  139.  
  140.   If editValues(0) <> trueNames(entryIndex) OR editValues(3) <> visibility Then
  141.     If editValues(3) = true Then _
  142.         fullDestination = visibleMenuExt & "\" & editValues(0) Else _
  143.         fullDestination = unvisibleMenuExt & "\" & editValues(0)
  144.     If RegistryChanged = true Then Exit Sub
  145.     If entryIndex <> 0 Then moveSubKey  fullName, fullDestination _
  146.     Else RegWriteValue fullDestination & "\@", "", 1
  147.     changed = true
  148.     fullName = fullDestination
  149.   End If
  150.  
  151.   If IsEmpty(editValues(1)) = true Then
  152.     If changed = true Then
  153.       IndicateSettingChange
  154.       Plugin_Initialize 
  155.     End If
  156.     Exit Sub
  157.   End If
  158.   RegWriteValue fullName & "\@", editValues(1), 1 
  159.   
  160.   If IsEmpty(editValues(2)) = true Then
  161.     If changed = true Then
  162.       IndicateSettingChange
  163.       Plugin_Initialize
  164.     End If
  165.     Exit Sub
  166.   End If 
  167.   If editValues(2) = "" Then
  168.     If RegValueExists(fullName & "\contexts") = true Then _
  169.     RegDeleteValue fullName & "\contexts"
  170.   Else
  171.     RegWriteValue fullName & "\contexts", editValues(2), 3 
  172.   End If
  173.  
  174.   If changed = true Then
  175.     IndicateSettingChange
  176.     Plugin_Initialize 
  177.   End If  
  178. End Sub
  179.  
  180.  
  181. Sub addEntry
  182.   editEntry 0 
  183. End Sub
  184.  
  185.  
  186. Sub deleteEntry (entryIndex)
  187.   If entryIndex > visibleCount Then
  188.     deleteSubKey unvisibleMenuExt & "\" & trueNames(entryIndex)
  189.   Else
  190.     deleteSubKey visibleMenuExt & "\" & trueNames(entryIndex)
  191.     IndicateSettingChange
  192.   End If
  193.  Plugin_Initialize
  194. End Sub
  195.  
  196.  
  197. 'show input windows
  198. 'check, convert and save input values
  199. Function DataInput(inputIndex, fullKeyName, namesIndex, ByRef values)
  200.          'show input windows with values
  201.   Select Case inputIndex
  202.     Case 1          'entry name
  203.      text = "Enter context menu name, which can include an ampersand character to cause " & _
  204.             "the character that follows to be underlined and used as a shortcut key:"
  205.   value = trueNames(namesIndex)
  206.     Case 2          'default URL
  207.      text = "Enter URL of the page that contains the script, which you want to execute:" & vbCrLf & _
  208.             "(if URL is empty, IE shows this entry not!)"
  209.      If namesIndex <> 0 Then value = RegReadValue(fullKeyName & "\@") _
  210.      Else value = ""
  211.     Case 3          'contexts
  212.      text = "Which contexts this entry should appear? " & _
  213.             "Use the logical OR of the following values:" & vbCrLf & _
  214.             "00000001-default" & vbTab & "00001000-tables" & vbCrLf & _
  215.             "00000010-images" & vbTab & "00010000-selection   " & vbCrLf & _ 
  216.             "00000100-controls" & vbTab & "00100000-anchor"
  217.       If namesIndex <> 0 Then 
  218.      If RegValueExists(fullKeyName & "\contexts")=true Then _
  219.         valueType=RegValueType(fullKeyName & "\contexts")  
  220.         value = RegReadValue(fullKeyName & "\contexts")
  221.      If value <> Empty Then
  222.        'convert only last byte
  223.        If valueType=3 Then value=CLng("&H" & Right(value,2))
  224.        If valueType=2 OR valueType=3 Then value=dez2bin(value)
  225.      Else
  226.        value = ""
  227.      End If
  228.       Else
  229.         value = "00000001"
  230.       End If
  231.     Case 4          'visibility
  232.      text = "Are you want to make this entry visible (Yes/No)?"
  233.      If namesIndex > visibleCount Then value = "No" Else value = "Yes"
  234.     Case Else
  235.      Err.Raise vbObjectError + 1, "Function DataInput", "inputIndex (" & inputIndex & ") is out of bound (4)!" 
  236.   End Select
  237.  
  238.   Do         'check input data
  239.     reinput = false
  240.     answer = InputWindow(text,value,1)
  241.     If IsEmpty(answer) = true Then Exit Function
  242.   
  243.          'syntax check and data convert
  244.     Select Case inputIndex
  245.       Case 1          'entry name
  246.         If Trim(answer) = "" Then 
  247.           reinput = true
  248.         ElseIf Len(Trim(answer)) > 1 Then
  249.           If Left(Trim(answer),2)=Left(uMark,2) OR Left(Trim(answer),2)=Left(vMark,2) Then
  250.             MsgWarning "Names, which begin with " & _
  251.                     uMark & "or " & vMark & _
  252.                     "are not allowed!"
  253.             reinput = true
  254.           End If
  255.         End If
  256.  
  257.         If reinput = false Then        
  258.           If LCase(answer) <> LCase(trueNames(namesIndex)) Then
  259.             For c=1 To UBound(trueNames)
  260.               If LCase(answer) = LCase(trueNames(c)) Then
  261.                 MsgWarning "This name already exists!"
  262.                 reinput = true
  263.                 Exit For
  264.               End If
  265.             Next
  266.           End If
  267.         End If
  268.       Case 2          'default URL
  269.         If Trim(answer) = "" AND answer <> "" Then reinput = true
  270.       Case 3          'contexts
  271.         If answer = "" Then
  272.           'nothing to do
  273.         ElseIf Len(answer)=8 Then
  274.           For i=1 To Len(answer)
  275.            char = Mid(answer,i,1)
  276.            Select Case char
  277.             Case "0", "1"
  278.               filtredAnswer = filtredAnswer & char
  279.             Case Else
  280.               'nothing to do
  281.            End Select
  282.           Next
  283.           If answer = filtredAnswer Then
  284.             answer = bin2hex(answer)
  285.           Else
  286.             reinput = true
  287.           End If
  288.         Else
  289.           reinput = true
  290.         End If
  291.       Case 4          'visibility
  292.         If LCase(answer)="yes" Then
  293.           answer = true
  294.         ElseIf LCase(answer)="no" Then
  295.           answer = false
  296.         Else
  297.           reinput = true
  298.         End If
  299.       Case Else
  300.         'unpossible
  301.     End Select
  302.     value = answer
  303.   Loop While reinput = true 
  304.     
  305.   values(inputIndex-1) = answer
  306.   
  307.   DataInput = answer
  308. End Function
  309.  
  310.  
  311. Function bin2hex(binValue)
  312.  For i=0 To 7
  313.   dezValue = dezValue + Mid(binValue,8-i,1)*2^(i)
  314.  Next
  315.  bin2hex = Hex(dezValue)
  316.  If Len(bin2hex) = 1 Then bin2hex = "0" & bin2hex 
  317. End Function
  318.  
  319.  
  320. 'convert only last byte
  321. Function dez2bin(ByVal dezValue)
  322.   For i=1 to 8
  323.    bit = (dezValue Mod 2) & bit
  324.    dezValue = dezValue \ 2
  325.   Next
  326.   dez2bin = bit
  327. End Function
  328.  
  329.  
  330. Sub moveSubKey (fullSourceKey, fullDestinationKey)
  331.   dim i, j
  332.   dim pathsCount, valuesCount
  333.   dim defaultString, value, data, dataType
  334.     
  335.     pathsCount = RegEnumPaths(fullSourceKey)
  336.     If pathsCount <> 0 Then
  337.       For j=1 to pathsCount
  338.        moveSubKey fullSourceKey & "\" & RegEnumElement(j), fullDestinationKey & "\" & RegEnumElement(j)
  339.       Next
  340.     End If
  341.     
  342.     defaultString = RegReadValue(fullSourceKey & "\@")
  343.     RegWriteValue fullDestinationKey & "\@", defaultString, 1
  344.  
  345.     valuesCount = RegEnumValues(fullSourceKey)
  346.     For i=1 to valuesCount
  347.        value = RegEnumElement(i)
  348.        data = RegReadValue(fullSourceKey & "\" & value)
  349.        dataType = RegValueType(fullSourceKey & "\" & value)
  350.        RegWriteValue fullDestinationKey & "\" & value, data, dataType 
  351.        RegDeleteValue fullSourceKey & "\" & value
  352.     Next
  353.     RegDeletePath fullSourceKey
  354. End Sub
  355.  
  356.  
  357. Sub deleteSubKey (fullName)
  358.  dim x, y
  359.  dim values, pathsCount
  360.    pathsCount = RegEnumPaths(fullName)
  361.    If pathsCount <> 0 Then
  362.     For x=1 to pathsCount
  363.      deleteSubKey fullName & "\" & RegEnumElement(x)
  364.     Next
  365.    End If
  366.  
  367.    values = RegEnumValues(fullName)
  368.    For y=1 to values
  369.     valueName = RegEnumElement(y)
  370.     RegDeleteValue fullName & "\" & valueName
  371.    Next
  372.    RegDeletePath fullName
  373. End Sub
  374.  
  375. 'Check, if IE settings in Registry were meantime for example manual changed.
  376. 'If yes, plug-in restarts.
  377. Function RegistryChanged
  378.   If visibleMenuExists <> RegPathExists(visibleMenuExt) Then
  379.       IndicateSettingChange
  380.       RestartMessage
  381.       RegistryChanged = true
  382.       Exit Function
  383.   ElseIf visibleMenuExists = true Then
  384.       If visibleCount <> RegEnumPaths(visibleMenuExt) Then
  385.  IndicateSettingChange
  386.        RestartMessage
  387.        RegistryChanged = true
  388.        Exit Function
  389.       End If
  390.   End If
  391.   
  392.   If unvisibleMenuExists <> RegPathExists(unvisibleMenuExt) Then
  393.       RestartMessage
  394.       RegistryChanged = true
  395.       Exit Function
  396.   ElseIf unvisibleMenuExists = true Then
  397.       If unvisibleCount <> RegEnumPaths(unvisibleMenuExt) Then
  398.        RestartMessage
  399.        RegistryChanged = true
  400.        Exit Function
  401.       End If
  402.   End If
  403.  
  404.   For i=1 to visibleCount
  405.     If RegPathExists(visibleMenuExt & "\" & trueNames(i)) = false Then
  406.       IndicateSettingChange
  407.       RestartMessage
  408.       RegistryChanged = true
  409.       Exit Function
  410.     End If
  411.   Next
  412.  
  413.   elCount = visibleCount + unvisibleCount
  414.   For i=visibleCount + 1 to elCount
  415.     If RegPathExists(unvisibleMenuExt & "\" & trueNames(i)) = false Then
  416.       RestartMessage
  417.       RegistryChanged = true
  418.       Exit Function
  419.     End If
  420.   Next
  421.   
  422.   RegistryChanged = false
  423. End Function
  424.  
  425.  
  426. Sub RestartMessage
  427.   Plugin_Initialize
  428.   MsgWarning "Plug-in is restarted, because" & vbCrLf & _
  429.         "Registry was changed!" & vbCrLf & "Your changes were not applied."
  430. End Sub
  431.  
  432.  
  433. Sub Plugin_Terminate
  434. End Sub
  435.